﻿using CMWVS.Core;
using Microsoft.VisualStudio.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bleissem.CMWVS.Commands
{
    public abstract class BaseCommand : OleMenuCommand
    {
        #region Constructor

        private BaseCommand()
            : base(null, null)
        {
        }

        public BaseCommand(CommandID id)
            : base(OnExecute, id)
        {
            base.BeforeQueryStatus += BaseCommandBeforeQueryStatus;
        }

        #endregion Constructor

        internal virtual void Initialize(MainViewModel mvm, Resolver resolver)
        {
            this.m_MainViewModel = mvm;
            this.Resolver = resolver;
        }

        protected MainViewModel m_MainViewModel
        {
            get;
            private set;
        }

        protected Resolver Resolver
        {
            get;
            private set;
        }

        private static void BaseCommandBeforeQueryStatus(object sender, EventArgs e)
        {
            BaseCommand command = sender as BaseCommand;
            if (command != null)
            {
                command.OnBeforeQueryStatus();
            }
        }

        protected virtual void OnBeforeQueryStatus()
        {
        }

        private static void OnExecute(object sender, EventArgs e)
        {
            BaseCommand command = sender as BaseCommand;
            if (command != null)
            {
                command.Execute();
            }
        }

        protected abstract void Execute();
    }
}